//
//  CAPVisitorViewController.swift
//  CAPSwift
//
//  Created by captain on 16/4/18.
//  Copyright © 2016年 captain. All rights reserved.
//

import UIKit

class CAPVisitorViewController: UITableViewController {
    //状态
    var isLogin: Bool = CAPUserAccountTools.sharedTools.isLogin
    
    var visitorView: CAPVisitorView?
    
    override func loadView() {
        //三目运算
        isLogin ? super.loadView() : setupVisitorView()
        
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    // MARK: - 设置视图
    private func setupVisitorView(){
        setupNav()
        visitorView = CAPVisitorView()
        visitorView?.visitorClosure = {
            self.login()
        }
        view = visitorView
        
    }
    
    
    // MARK: - 导航栏
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        
    }
    
    // MARK: - 点击事件
    @objc private func login(){
        let oauthVC = CAPOAuthViewController()
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    
    
    
    
}
